package com.da.lon.wang.xlg.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.da.lon.wang.xlg.MyApplication;
import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.bean.PartyFragmentBean.PartyResult.PartyResultList.PartyResultProList;

import java.util.ArrayList;

public class NewHeadLvAdapter extends BaseAdapter {

    HolderHead holder;
    private LayoutInflater inflater;
    private Context context;
    private ArrayList<PartyResultProList> proDatas;
    private String id = null;

    public NewHeadLvAdapter(Context context,
                            ArrayList<PartyResultProList> proDatas) {
        this.context = context;
        this.proDatas = proDatas;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return proDatas == null ? 0 : proDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        // 活动页面列表项
        try {
            if (convertView == null) {
                holder = new HolderHead();
                convertView = inflater.inflate(
                        R.layout.list_item_lv_item, null);

                holder.svImageView = (ImageView) convertView
                        .findViewById(R.id.list_item_sv_img);
                holder.svNameTextView = (TextView) convertView
                        .findViewById(R.id.list_item_sv_name);
                holder.svPriceTextView = (TextView) convertView
                        .findViewById(R.id.list_item_sv_price);
                holder.svPriceSpeTextView = (TextView) convertView
                        .findViewById(R.id.list_item_sv_pricespe);
                convertView.setTag(holder);
            } else {
                holder = (HolderHead) convertView.getTag();
            }

            MyApplication.loadImageByPicasso(context, proDatas.get(position)
                    .getBigimage(), null, holder.svImageView, 150, 150, 1);
            holder.svNameTextView.setText(proDatas.get(position).getName());
            holder.svPriceTextView.setText("￥" + proDatas.get(position).getPrice());
            holder.svPriceTextView.getPaint().setFlags(
                    Paint.STRIKE_THRU_TEXT_FLAG);
            holder.svPriceSpeTextView.setText("￥" + proDatas.get(position).getSeal_price());
        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }
}

class HolderHead {
    public TextView svPriceSpeTextView;
    public TextView svPriceTextView;
    public TextView svNameTextView;
    public ImageView svImageView;
    ImageView list_head_item_imgv;
}
